﻿using System;
using System.Windows.Threading;
using Ipmce.RemoteVoting.Frontend.VotingApplication.Utils;

namespace Ipmce.RemoteVoting.Frontend.VotingApplication.ViewModel
{
	class NotifyingDateTimeViewModel : ViewModelBase, IDateTimeProvider
	{
		public NotifyingDateTimeViewModel()
		{
			_now = DateTime.Now;
			var timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(100)};

			timer.Tick += TimerTick;

			timer.Start();
		}

		public DateTime Now
		{
			get { return _now; }
			private set
			{
				_now = value;
				OnPropertyChanged("Now");
			}
		}

		private void TimerTick(object sender, EventArgs e)
		{
			Now = DateTime.Now;
		}
		private DateTime _now;

	}
}
